package csu.web.mypetstore.service;

import csu.web.mypetstore.domain.Account;
import csu.web.mypetstore.persistence.LogDao;
import csu.web.mypetstore.domain.Log;
import csu.web.mypetstore.persistence.impl.LogDaoImpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class LogService {
    private LogDao logDAO;

    public LogService() {
        logDAO=new LogDaoImpl();
    }

    public List<Log> getLog(Account account){
        return logDAO.getLog(account);
    }

    public void updateLog(List<Log> logList,String message,Account account){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        Log log=new Log(dateFormat.format(date),message);
        logList.add(log);
        if (logList.size()==10){
            logList.remove(0);
        }
        logDAO.updateLog(logList,account);
    }
}
